﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using MDCAdminTool.Controls;

namespace MDCAdminTool.Commands
{
    public class SearchDataCache : AddTabCommandBindingBase
    {
        public SearchDataCache()
        {
            Command = Application.Current.Resources["SearchDataCacheCommand"] as ICommand;
            CanExecute += OnCanExecute;
            Executed   += OnExecuted;                
        }

        protected override void OnExecuted( object sender , ExecutedRoutedEventArgs e )
        {
            var cache = e.Parameter as MdcCache;
            CacheRegion cr = null;

            if ( cache == null )
            {
                cr = e.Parameter as CacheRegion;

                if ( cr != null )
                    cache = cr.Parent as MdcCache;
            }

            if ( cache != null )
            {
                try
                {
                    var win = new MDCAdminTool.Controls.SearchDataCache(cache);
                    //win.Show();
                    AddNewTab("Search in " + cache.Name ,win);
                }
                catch { }
            }
        }
        //protected void OnCanExecute( object sender , CanExecuteRoutedEventArgs e )
        //{
        //    e.CanExecute = true;
        //}
    }
}
